using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using EpicBall.ScreenSystem;
using EpicBall.Levels;
using System.Diagnostics;

namespace EpicBall
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class EpicBall : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        GameStack gameStack;
        public EpicBall()
        {
            graphics = new GraphicsDeviceManager(this);
            gameStack = new GameStack(this);
            Components.Add(gameStack);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth = 1280;
            graphics.PreferredBackBufferHeight = 720;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();
            Window.Title = "Epic Ball - Alpha 0.0.2";

            if (!Directory.Exists(gameStack.GetSavePath))
            {
                Directory.CreateDirectory(gameStack.GetSavePath);
            }

            if (!File.Exists(gameStack.GetSavePath + "\\plains.hs"))
            {
                StreamWriter sr = new StreamWriter(gameStack.GetSavePath + "\\plains.hs");
                sr.WriteLine("0");
                sr.Close();
            }

            if (!File.Exists(gameStack.GetSavePath + "\\desert.hs"))
            {
                StreamWriter sr = new StreamWriter(gameStack.GetSavePath + "\\desert.hs");
                sr.WriteLine("0");
                sr.Close();
            }

            if (!File.Exists(gameStack.GetSavePath + "\\space.hs"))
            {
                StreamWriter sr = new StreamWriter(gameStack.GetSavePath + "\\space.hs");
                sr.WriteLine("0");
                sr.Close();
            }

            /*MenuScreen menu = new MenuScreen();
            Texture2D newGame = Content.Load<Texture2D>("MainMenu/newgame_btn");
            TestLevel test = new TestLevel();
            menu.AddMenuButton(new MenuButton(menu, test, newGame, new Vector2(400, 300)));*/
            MainMenu menu = new MainMenu(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            gameStack.AddScreen(menu);
            base.Initialize();
        }
    }
}